package com.hu.hutool.Convert;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.CharsetUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @Author CazCen
 * @Date 2021/10/12 22:16
 */

/**
 * Convert 工具类
 * 测试用例见
 */

@Slf4j
public class UserConvert {
    /**
     *
     */

    public static void IntegerToStr() {
        Integer a = 1;
        String s = Convert.toStr(a, "0");
        log.info("s:{}", s);
    }

    public static void ArrayToString() {
        long[] b = {1, 2, 3, 4, 5, 6};
        String s = Convert.toStr(b);
        log.info("ArrayToString:{}", s);
    }

    public static void convertTime() {
        long timeMillis = System.currentTimeMillis();
        long Second = Convert.convertTime(timeMillis, TimeUnit.MILLISECONDS, TimeUnit.SECONDS);
        log.info("timeMillis:{}", timeMillis);
        log.info("Second:{}", Second);
    }

    public static void toIntArray() {
        String[] b = {"1", "2", "3", "4"};
        Integer[] intArray = Convert.toIntArray(b);
        log.info("intArray:{}", intArray.length);
        long[] c = {1, 2, 3, 4, 5, 5, 5};
        Integer[] intArray2 = Convert.toIntArray(c);
        log.info("intArray2:{}", Arrays.stream(intArray2).count());
    }

    public static void toDate() {
        String a = "2021-10-12 10:10:10";
        Date value = Convert.toDate(a);
        System.out.println(value.getTime());
    }

    public static void toList() {
        String[] a = {"a", "你", "好", "", "1"};
        List<?> objects = Convert.toList(a);

    }

    /**
     * 半角转全角
     */
    public static void toSBC() {
        String a = "123456789";
        String sbc = Convert.toSBC(a);
        log.info("sbc:{}", sbc);
    }

    /**
     * 全角转半角
     */
    public static void toDBC() {
        String a = "１２３４５６７８９";
        String dbc = Convert.toDBC(a);
        log.info("dbc:{}", dbc);
    }

    /**
     * 转为16进制（Hex）字符串
     */
    public static void toHex() {
        String str = "我是一个小小的可爱的字符串";
        String s = Convert.toHex(str, CharsetUtil.CHARSET_UTF_8);
        log.info("str:{},hex:{}", str, s);
    }

    /**
     * 将16进制（Hex）字符串转为普通字符串:
     */
    public static void hexToStr() {
        String hex = "e68891e698afe4b880e4b8aae5b08fe5b08fe79a84e58fafe788b1e79a84e5ad97e7aca6e4b8b2";
        String raw = Convert.hexToStr(hex, CharsetUtil.CHARSET_UTF_8);

        log.info("hex:{},raw:{}", raw);

    }

    /**
     * 与16进制类似，Convert类同样可以在字符串和Unicode之间轻松转换：
     */
    public static void unicodeToStr() {
        String a = "我是一个小小的可爱的字符串";
        //结果为："\\u6211\\u662f\\u4e00\\u4e2a\\u5c0f\\u5c0f\\u7684\\u53ef\\u7231\\u7684\\u5b57\\u7b26\\u4e32"
        String unicode = Convert.strToUnicode(a);
        //结果为："我是一个小小的可爱的字符串"
        String raw = Convert.unicodeToStr(unicode);
    }

    /**
     * 金额大小写转换
     */
    public static void digitToChinese() {
        double a = 67556.32;

        //结果为："陆万柒仟伍佰伍拾陆元叁角贰分"
        String digitUppercase = Convert.digitToChinese(a);
        log.info("a:{},digitUppercase:{}", a, digitUppercase);
    }
}
